package com.jxc.service.impl;

import com.jxc.VO.GoodsVO;
import com.jxc.mapper.GoodsMapper;
import com.jxc.pojo.GoodsExample;
import com.jxc.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class GoodsServiceImpl implements GoodsService{
    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public List<GoodsVO> list(String codeOrName) {
        GoodsExample goodsExample = new GoodsExample();
        if(codeOrName != null && !"".equals(codeOrName)) {
            boolean matches = codeOrName.matches("[0-9]+");
            if(matches){
                System.out.println("全部是数字==="+codeOrName);
                codeOrName = "%"+codeOrName+"%";
                goodsExample.createCriteria().andCodeLike(codeOrName);
            }else{
                System.out.println("不是数字==="+codeOrName);
                codeOrName = "%"+codeOrName+"%";
                goodsExample.createCriteria().andNameLike(codeOrName);
            }


        }

        return goodsMapper.selectByExample(goodsExample);
    }

    @Override
    public List<GoodsVO> findGoods(String codeOrName) {
        return goodsMapper.findGoods(codeOrName);
    }

    @Override
    public Long getCount() {
        GoodsExample goodsExample = new GoodsExample();
        return goodsMapper.countByExample(goodsExample);
    }
}
